package com.example.recite_words.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.example.recite_words.Bean.Questions;
import com.example.recite_words.MainActivity;
import com.example.recite_words.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

public class Win extends AppCompatActivity {
    private TextView mScore,uScore;
    private Button but1,but2;
    private CircleImageView my,your;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_win);
        Intent intent=getIntent();
        int myScore=intent.getIntExtra("myScore",0);
        int urScore=intent.getIntExtra("urScore",0);
        my = findViewById(R.id.win_myicon);
        Uri uri = MainActivity.TheUser.IconToUri();
        if(uri != null){
            my.setImageURI(uri);
        }
        else {
            my.setImageResource(R.drawable.user_icon);
        }
        your = findViewById(R.id.win_youricon);
        uri = MainActivity.en_user.IconToUri();
        if(uri != null){
            your.setImageURI(uri);
        }
        else {
            your.setImageResource(R.drawable.user_icon);
        }
        ArrayList<Questions> wrongList;
        wrongList=(ArrayList<Questions>) getIntent().getSerializableExtra("wrongList");
        mScore = (TextView)findViewById(R.id.mScore);
        uScore = (TextView)findViewById(R.id.uScore);
        mScore.setText(myScore+"");
        uScore.setText(urScore+"");

        ListView listView = (ListView)this.findViewById(R.id.wrongList);
        List<HashMap<String, Object>> data = new ArrayList<HashMap<String, Object>>();
        for(int i = 0; i < wrongList.size(); i++){
            HashMap<String, Object>item = new HashMap<String, Object>();
            item.put("word", wrongList.get(i).word);
            item.put("translation", wrongList.get(i).true_meaning);
            data.add(item);
        }
        SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.item,
                new String[]{"word", "translation"}, new int[]{R.id.word, R.id.translation});
        //实现列表的显示
        listView.setAdapter(adapter);



        but1=(Button)findViewById(R.id.exit);
        but2=(Button)findViewById(R.id.again);
        but1.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Win.this,Main.class);
                startActivity(intent);
            }
        });
        but2.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Win.this,Waiting.class);
                startActivity(intent);
            }
        });

    }
}